package stu3;

import javax.sound.midi.Soundbank;
import java.util.Scanner;

public class StuTest {

    //    int[] stus=new int[20];
    Student[] stus1 = new Student[20];
    Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        StuTest st = new StuTest();
        st.start();
    }

    private void start() {
        int choose;//定义选择的变量，注意他的作用范围
        do {
            printSysInfo();
            choose = input.nextInt();
            switch (choose) {
                case 1:
                    addStu();
                    break;
                case 2:
                    delStu();
                    break;
                case 3:
                    queryStu();
                    break;
                case 0:
                    System.out.println("xx");
            }
        } while (choose != 0);
    }

    private void queryStu() {
        System.out.println("学号\t性别\t姓名\t年龄");
        for(Student stu:stus1){
            //判断学生不能为null
            if(stu!=null){
                stu.printStu();
            }

        }
    }

    private void delStu() {
        System.out.println("输入学号");
        int num = input.nextInt();
        for (int i = 0; i < stus1.length; i++) {
            //进行一个为空的判断
            if (stus1[i]!=null&&num == stus1[i].xue) {
                stus1[i] = null;
                break;
            }
        }
    }

    private void addStu() {
        System.out.println("--添加学生--");
        System.out.println("添加学号");
        int ID = input.nextInt();
        System.out.println("添加姓名");
        String name1 = input.next();
        System.out.println("添加性别");
        String sex1 = input.next();
        System.out.println("添加年龄");
        int age1 = input.nextInt();
        //创建学生对象
        Student stu = new Student(ID, name1, sex1, age1);
        //循环数组找出空的位置，放入新建的对象
        for (int i = 0; i < stus1.length; i++) {
            if (stus1[i] == null) {
                stus1[i] = stu;
//                break;
                return;//结束循环
            }
        }

    }

    private void printSysInfo() {
        System.out.println("--学生管理系统--");
        System.out.println("1添加学生");
        System.out.println("2删除学生");
        System.out.println("3查询学生");
        System.out.println("0退出");
        System.out.println("请选择");


    }

}
